<?php
/**
 * 
 * @author huangjian E-mail:870596179@qq.com
 * @version 创建时间：2016年10月25日 下午3:45:14 
 * 类说明
 */
class HotKeywordAction extends BaseAction{
	/**
	 * @authority 浏览
	 */
	public function index(){
		$this->display('index');
	}
	
	//列表
	public function getAllData(){
		$Model = M($this->getActionName());
		$map = $this->loadSeachCondition();
		$map['flag'] = 1;
		$total = $Model->where($map)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		$data = $Model->where($map)->limit($page->firstRow,$page->listRows)->order($page->sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
	
	/**
	 * 组装条件
	 * @return multitype:multitype:string
	 */
	public function loadSeachCondition(){
		$map = array();
		return $map;
	}
	
	/**
	 * @authority 新增
	 */
	public function add(){
		$Model = M($this->getActionName());
		$map['flag'] = 1;
		$total = $Model->where($map)->count();// 查询满足要求的总记录数
		$this->assign("total",$total);
		$this->display('add');
	}
	
	/**
	 * 插入
	 */
	public function insert(){
		$Model = M($this->getActionName());
		unset ( $_POST [$Model->getPk()] );
		if (false === $Model->create()) {
			$this->error($Model->getError());
		}
		$where['flag'] = 1;
		$count = $Model->where($where)->count();
		if($count < 10){
			//保存当前数据对象
			if ($result = $Model->add()) { //保存成功
				$this->ajaxReturn(1,L('ADMIN_ADD_SUCCESS'),1);
			} else {
				$this->ajaxReturn(0,L('ADMIN_ADD_ERROR'),0);
			}
		}{
			$this->ajaxReturn(0,"添加失败，关键词最多添加10个！",0);
		}
	}
}